#include "dialogvisualize.h"
#include "ui_dialogvisualize.h"

DialogVisualize::DialogVisualize(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::DialogVisualize)
{
    ui->setupUi(this);
    setWindowTitle("Visualize The Results");

}

DialogVisualize::~DialogVisualize()
{
    delete ui;
}

void DialogVisualize::on_pushButton_Init_clicked()
{
    ui->viewer->dataFile0=eventName+"/ProcessedResults/cam0_3Dpts.yml.gz";
    ui->viewer->dataFile1=eventName+"/ProcessedResults/cam1_3Dpts.yml.gz";
    ui->viewer->triangleFileName=eventName+"/ProcessedResults/visTriangles.yml";
    ui->pushButton_Init->setText("Reading...");
    ui->pushButton_Init->setEnabled(false);
    ui->viewer->loadResultFile();

}


void DialogVisualize::on_cancelButton_clicked()
{
    close();
}


void DialogVisualize::dataDone()
{
    ui->pushButton_Init->setText("DONE");

    if(ui->viewer->showCam0){
        ui->Cam0CheckBox->setEnabled(true);
        ui->Cam0CheckBox->setChecked(true);
    }

    if(ui->viewer->showCam1){
        ui->Cam1CheckBox->setEnabled(true);
        ui->Cam1CheckBox->setChecked(true);
    }

    if(ui->viewer->showTriangles){
        ui->TriangleCheckBox->setEnabled(true);
        ui->TriangleCheckBox->setChecked(true);
    }

    ui->viewer->startAnimation();  //start the animation
}

void DialogVisualize::on_Cam0CheckBox_clicked(bool checked)
{
    ui->viewer->showCam0=checked; //toggle the data points from Cam0 to be shown
    ui->viewer->updateGL(); //update, if not animating  (its automatic if animation is running)

}
void DialogVisualize::on_Cam1CheckBox_clicked(bool checked)
{
    ui->viewer->showCam1=checked;    //toggle the data points from Cam1 to be shown
    ui->viewer->updateGL(); //update, if not animating  (its automatic if animation is running)

}

void DialogVisualize::on_checkBox_TankGeom_clicked(bool checked)
{
   ui->viewer->showTankGeom=checked;  //toggle the tank Geometry display
   ui->viewer->updateGL(); //update, if not animating  (its automatic if animation is running)

}

void DialogVisualize::on_pushButton_clicked()
{
    if(ui->viewer->animationIsStarted()) {
        ui->viewer->stopAnimation();
        ui->pushButton->setText("Play");
    }
    else {
        ui->viewer->startAnimation();
        ui->pushButton->setText("Pause");
    }
}

void DialogVisualize::on_TriangleCheckBox_clicked(bool checked)
{
    ui->viewer->showTriangles=checked;    //toggle the triangles to be shown
    ui->viewer->updateGL(); //update, if not animating  (its automatic if animation is running)

}

void DialogVisualize::on_checkBox_Tubing_clicked(bool checked)
{
    ui->viewer->showTubing=checked;
    ui->viewer->updateGL(); //update, if not animating  (its automatic if animation is running)
}
